<template>
  <div>
    <el-table :data="tableData" stripe style="width: 100%" max-height="600">
      <el-table-column prop="name" label="" width="50">
        <template slot-scope="scope">
          <span class="el-icon-bottom"></span>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="名称" show-overflow-tooltip>
      </el-table-column>
      <el-table-column
        prop="auditorList"
        label="审核角色"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{ auditRolesNames(scope.row) }}
        </template>
      </el-table-column>
      <el-table-column prop="extFiled" label="协同角色" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ extFiledRolesNames(scope.row) }}
        </template>
      </el-table-column>
      <el-table-column
        prop="auditRelation"
        label="审核关系"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <span v-show="scope.row.auditRelation == 'and'">所有人都需审核</span>
          <span v-show="scope.row.auditRelation == 'or'">任一人审核即可</span>
        </template>
      </el-table-column>
      <el-table-column prop="des" label="描述">
        <template slot-scope="scope">
          <p class="sheng">{{ scope.row.des || '--' }}</p>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="180">
      </el-table-column>
      <el-table-column label="操作" width="140">
        <template slot-scope="{ row }">
          <el-button-group>
            <el-button
              type="primary"
              size="mini"
              @click="handleEdit(row)"
              :disabled="row.step < 0"
              >编辑</el-button
            >
            <el-button
              type="danger"
              size="mini"
              @click="handleDelete(row)"
              :disabled="row.step < 0"
              >删除</el-button
            >
          </el-button-group>
          <!-- :disabled="flowData.status == 1" -->
        </template>
      </el-table-column>
      <div slot="empty" class="emptyBg">
        <el-empty :image-size="200"></el-empty>
      </div>
    </el-table>
    <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    />
  </div>
</template>
<script>
import {
  flowDefinitionNodeQuery,
  flowDefinitionNodeDelete,
} from '@/api/admin/audit/flowDefinitionNode.js'
import Bus from '@/utils/bus.js'
export default {
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        definitionCode: '',
      },
      tableData: [],
      pageObj: {},
    }
  },
  computed: {
    auditRolesNames() {
      return function (v) {
        if (v.auditRoles && v.auditRoles.length) {
          return v.auditRoles.map((m) => m.name).toString()
        } else {
          return '--'
        }
      }
    },
    extFiledRolesNames() {
      return function (v) {
        if (v.extFiledRoles && v.extFiledRoles.length) {
          return v.extFiledRoles.map((m) => m.name).toString()
        } else {
          return '--'
        }
      }
    },
  },
  props: ['flowData'],
  mounted() {
    this.getList()
    Bus.$on('refreshFlowNodeList', (v) => {
      if (v) {
        Object.assign(this.listQuery, v)
      }
      this.getList()
    })
  },
  beforeDestroy() {
    Bus.$off('refreshFlowNodeList')
  },
  methods: {
    getList() {
      this.listQuery.definitionCode = this.flowData.code
      flowDefinitionNodeQuery(this.listQuery).then((res) => {
        this.tableData = res.data.data
        this.pageObj = res.data
      })
    },
    //编辑
    handleEdit(row) {
      Bus.$emit('showDialogFlowNodeAdd', row)
    },
    //删除确认
    handleDelete(row) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.delete(row)
        })
        .catch(() => {})
    },
    //删除
    delete(row) {
      flowDefinitionNodeDelete(row.id).then((res) => {
        this.getList()
        this.$message({
          message: '操作成功',
          type: 'success',
        })
      })
    },
  },
}
</script>